<?php
 Session_Start () ;
 Include ("../../include/garennes.cfg") ;
 Include ("../../include/init.php") ;
 Include ("../include/config.inc") ;
 Include ("../../include/garennes_apb.php") ;
 verif_droits ($droit_courant, $_SESSION ["code"]) ;

 $requete = var_courante ("requete", 0, null) ;
 $millesime = millesime (0) ;
 $ajax_requete = var_courante ("ajax_requete", 2, Null) ;
 If (IsSet ($ajax_requete) And (($ajax_requete == 1) Or ($ajax_requete == 2) Or ($ajax_requete == 3)))
  {
   If ($ajax_requete == 3)
    {
     $c1 = var_courante ("c1", 2, Null) ;
     $c2 = var_courante ("c2", 2, Null) ;
     If (garennes_apb_discipline_sconet_existe ($c2, $c1)) { $reponse = 1 ; } Else { $reponse = 0 ; }
     Header ("Content-Type: application/xml") ;
     Echo "<?xml version=\"1.0\"?><reponse>".$reponse."</reponse>" ;
    }
   Else
    {
     $car = var_courante ("car", 2, Null) ;
     Switch ($ajax_requete)
      {
       Default :
        Case 1 : $nom_champ = "code_gestion" ; $ordre = "libelle_court,code_matiere" ; Break ;
        Case 2 : $nom_champ = "code_matiere" ; $ordre = "code_matiere,libelle_court" ; Break ;
      }
     If (IsSet ($car) And ($car != ""))
      {
       $reponse = SQL_commande ("SELECT DISTINCT code_matiere,libelle_court,code_gestion FROM modalites WHERE ".$nom_champ." LIKE '%".$car."%' ORDER BY ".$ordre, $id_sql) ;
       $nbr_reponse = SQL_nbr_lignes ($reponse) ;
      }
     Else
      {
       $reponse = SQL_commande ("SELECT DISTINCT code_matiere,libelle_court,code_gestion FROM modalites ORDER BY ".$ordre, $id_sql) ;
       $nbr_reponse = SQL_nbr_lignes ($reponse) ;
       //$nbr_reponse = 0 ;
      }
     // Envoi de la reponse
     $reponse_code = $reponse_libelle = $reponse_gestion = "" ;
     For ($i = 0 ; $i < $nbr_reponse ; $i++)
      {
       $code = SQL_ligne_suivante ($reponse) ;
       $reponse_code .= "<code>".$code [0]."</code>" ;
       $reponse_libelle .= "<libelle>".$code [1]."</libelle>" ;
       $reponse_gestion .= "<gestion>".$code [2]."</gestion>" ;
      }
     Header ("Content-Type: application/xml") ;
     Echo "<?xml version=\"1.0\"?><reponse>".$reponse_code.$reponse_libelle.$reponse_gestion."</reponse>" ;
    }
   Exit ;
  }

 // APB
 $apb_actif = garennes_apb_actif ($millesime) ;

 $intitule_page = intitule_titre_affichage ("DISCIPLINE", "1|Discipline|Disciplines", $millesime) ;
 If (IsSet ($requete))
  {
   Switch ($requete)
    {
     // Insertion d'une discipline
     Case 0 : $id_type_discipline = var_courante ("id_type_discipline", 0, 0) ;
              $nom_long = var_courante ("nom_long", 0, "") ;
              $nom_court = var_courante ("nom_court", 0, "") ;
              $nom_bref = var_courante ("clef_gestion", 0, "") ;
              $code_disc = var_courante ("code_disc", 0, "") ;
              $type_disc = var_courante ("type_disc", 0, 0) ;
              $type_moyenne = var_courante ("type_moyenne", 0, 0) ;
              $type_arrondi = var_courante ("type_arrondi", 0, 0) ;
              $ok = SQL_commande ("INSERT INTO disciplines (id_type_discipline,nom_long,nom_court,nom_bref,code,millesime,type_discipline,type_moyenne,type_arrondi)
                                   VALUES ('".$id_type_discipline."','".$nom_long."','".$nom_court."','".$nom_bref."','".$code_disc."','".$millesime."','".$type_disc."','".$type_moyenne."','".$type_arrondi."')", $id_sql) ;
              $requete = 0 ;
              Break ;
     // Effacement d'une discipline
     Case 1 : $id_discipline = var_courante ("id_discipline", 0, 0) ;
              $code_disc = var_courante ("code_disc", 0, "") ;
              $ok = SQL_commande ("DELETE FROM disciplines WHERE id_discipline='".$id_discipline."' AND code='".$code_disc."' AND millesime='".$millesime."'", $id_sql) ;
              $ok = SQL_commande ("DELETE FROM options_eleves WHERE discipline='".$id_discipline."' AND code_disc='".$code_disc."' AND millesime='".$millesime."'", $id_sql) ;
              $ok = SQL_commande ("DELETE FROM services_classe WHERE discipline='".$id_discipline."' AND code_disc='".$code_disc."' AND millesime='".$millesime."'", $id_sql) ;
              $ok = SQL_commande ("DELETE FROM services_prof WHERE discipline='".$id_discipline."' AND code_disc='".$code_disc."' AND millesime='".$millesime."'", $id_sql) ;
              $ok = SQL_commande ("DELETE FROM phrases_specifiques WHERE id_discipline='".$id_discipline."'", $id_sql) ;
              $requete = 0 ;
              UnSet ($id_discipline) ;
              UnSet ($code_disc) ;
              Break ;
     // Debut de modification
     Case 2 : $id_discipline = var_courante ("id_discipline", 0, 0) ;
              $resultat = SQL_commande ("SELECT * FROM disciplines WHERE id_discipline='".$id_discipline."'", $id_sql) ;
              $modif = SQL_tableau_associatif ($resultat, "") ;
              $requete = 3 ;
              Break ;
     // Fin de modification
     Case 3 : $id_discipline = var_courante ("id_discipline", 0, 0) ;
              $id_type_discipline = var_courante ("id_type_discipline", 0, 0) ;
              $ancien_code = var_courante ("ancien_code", 0, 0) ;
              $nom_long = var_courante ("nom_long", 0, "") ;
              $nom_court = var_courante ("nom_court", 0, "") ;
              $nom_bref = var_courante ("clef_gestion", 0, "") ;
              $code_disc = var_courante ("code_disc", 0, "") ;
              $type_disc = var_courante ("type_disc", 0, 0) ;
              $type_moyenne = var_courante ("type_moyenne", 0, 0) ;
              $type_arrondi = var_courante ("type_arrondi", 0, 0) ;
              $ok = SQL_commande ("UPDATE disciplines SET id_type_discipline='".$id_type_discipline."',nom_long='".$nom_long."',nom_court='".$nom_court."',nom_bref='".$nom_bref."',code='".$code_disc."',millesime='".$millesime."',
                                                          type_discipline='".$type_disc."',type_moyenne='".$type_moyenne."',type_arrondi='".$type_arrondi."' WHERE id_discipline='".$id_discipline."'", $id_sql) ;
              $ok = SQL_commande ("UPDATE appreciations SET code_disc='".$code_disc."' WHERE discipline='".$id_discipline."' AND code_disc='".$ancien_code."' AND millesime='".$millesime."'", $id_sql) ;
              $ok = SQL_commande ("UPDATE controles SET code_disc='".$code_disc."' WHERE discipline='".$id_discipline."' AND code_disc='".$ancien_code."' AND millesime='".$millesime."'", $id_sql) ;
              $ok = SQL_commande ("UPDATE groupes_classe SET code_disc='".$code_disc."' WHERE discipline='".$id_discipline."' AND code_disc='".$ancien_code."' AND millesime='".$millesime."'", $id_sql) ;
              $ok = SQL_commande ("UPDATE groupes_eleve SET code_disc='".$code_disc."' WHERE discipline='".$id_discipline."' AND code_disc='".$ancien_code."' AND millesime='".$millesime."'", $id_sql) ;
              $ok = SQL_commande ("UPDATE options_eleve SET code_disc='".$code_disc."' WHERE discipline='".$id_discipline."' AND code_disc='".$ancien_code."' AND millesime='".$millesime."'", $id_sql) ;
              $ok = SQL_commande ("UPDATE services_classe SET code_disc='".$code_disc."' WHERE discipline='".$id_discipline."' AND code_disc='".$ancien_code."' AND millesime='".$millesime."'", $id_sql) ;
              $ok = SQL_commande ("UPDATE services_prof SET code_disc='".$code_disc."' WHERE discipline='".$id_discipline."' AND code_disc='".$ancien_code."' AND millesime='".$millesime."'", $id_sql) ;
              $ok = SQL_commande ("UPDATE sous_matieres SET code_disc='".$code_disc."' WHERE discipline='".$id_discipline."' AND code_disc='".$ancien_code."' AND millesime='".$millesime."'", $id_sql) ;
              $requete = 0 ;
              Break ;
     Case 4 : Include ("../../include/garennes_gestion_disciplines.php") ;
              garennes_mise_a_jour_types_disciplines ($millesime) ;
              $requete = 0 ;
              Break ;
     Case 5 : Include ("../../include/garennes_gestion_disciplines.php") ;
              garennes_effacer_disciplines_inutiles ($millesime) ;
              $requete = 0 ;
              Break ;
    }
  }
 Else
  { $requete = 0 ; }

 If (!IsSet ($modif))
  {
   $modif ["id_discipline"] = $modif ["nom_long"] = $modif ["nom_court"] = $modif ["nom_bref"] = $modif ["code"] = "" ;
   $modif ["id_type_discipline"] = $modif ["type_discipline"] = $modif ["type_moyenne"] = $modif ["type_arrondi"] = 0 ;
  }
 // MAJ des types de disciplines
 $ok = SQL_commande ("SELECT * FROM disciplines WHERE id_type_discipline='0' AND millesime='".$millesime."' LIMIT 1", $id_sql) ;
 If (SQL_nbr_lignes ($ok) == 1)
  {
   $resultat = SQL_commande ("SELECT t.id_type_discipline,d.id_discipline FROM disciplines d,types_disciplines t,codes_disciplines c WHERE d.code=c.code AND c.id_type_discipline=t.id_type_discipline AND t.id_type_discipline='0' AND d.millesime='".$millesime."'", $id_sql) ;
   For ($i = 0 ; $i < SQL_nbr_lignes ($resultat) ; $i++)
    {
     $r = SQL_ligne_suivante ($resultat) ;
     $req = "UPDATE disciplines SET id_type_discipline='".$r [0]."' WHERE id_discipline='".$r [1]."' LIMIT 1" ;
     $ok = SQL_commande ($req, $id_sql) ;
    }
  }

 $resultats = SQL_commande ("SELECT * FROM menus WHERE numero='".$droit_courant."' AND ordre='0' LIMIT 1", $id_sql) ;
 $l = SQL_tableau_associatif ($resultats, "") ;
 Echo "<html><head>" ;
 entete_html ("Garennes", "travail", 1) ;
 Echo styles ("none", "none", "none", $l ["lien"], "none") ;
 Include ("./gestion_disciplines.js") ;
 If ($apb_actif == 1)
  {
   Include ("../../include/garennes_ajax.php") ;
   Echo "<script type=\"text/javascript\">" ;
   Echo ajax_objet () ;
   Echo ajax_transmission () ;
   Echo "var codes_sconet=new Array;" ;
   Echo "var codes_gestion=new Array;" ;
   Echo "var requete=1;" ;
   Echo "function ajax_retour()" ;
   Echo "{" ;
   Echo  "if(requete!=3)" ;
   Echo  "{" ;
   // Requete
   Echo   "if(requete==1){nom_champ='code_gestion';}else{nom_champ='code_sconet';}" ;
   // Recherche des reponses
   Echo    "var items_code=objet_http.responseXML.getElementsByTagName('code');" ;
   Echo    "var items_libelle=objet_http.responseXML.getElementsByTagName('libelle');" ;
   Echo    "var items_gestion=objet_http.responseXML.getElementsByTagName('gestion');" ;
   // Boucle pour avoir tous les codes
   Echo    "if(items_code.length>0)" ;
   Echo     "{" ;
   Echo      "html='<select name=\"preselection\" id=\"preselection\" size=\"';" ;
   Echo      "if(items_code.length>5){html+='5';}else{html+=items_code.length;}" ;
   Echo      "html+='\" onclick=\"document.getElementById(\\'code_disc\\').value=codes_sconet[document.getElementById(\\'preselection\\').value];" ;
   Echo      "document.getElementById(\\'clef_gestion\\').value=codes_gestion[document.getElementById(\\'preselection\\').value];" ;
   Echo      "document.getElementById(nom_champ).innerHTML=\\'\\';" ;
   Echo      "requete=3;ajax_transmission(\\'./gestion_disciplines.php?ajax_requete=3&c1=\\'+document.getElementById(\\'clef_gestion\\').value" ;
   Echo      "+\\'&c2=\\'+document.getElementById(\\'code_disc\\').value,true,\\'ajax_retour\\');" ;
   Echo      "\">';" ;
   Echo      "for(i=0;i<items_code.length;i++)" ;
   Echo       "{" ;
   Echo       "codes_sconet[i]=items_code.item(i).firstChild.data;" ;
   Echo       "codes_gestion[i]=items_gestion.item(i).firstChild.data;" ;
   Echo       "html+='<option value=\"'+i+'\">';" ;
   Echo       "if(requete==1){" ;
   Echo       "html+=items_libelle.item(i).firstChild.data+' ('+items_code.item(i).firstChild.data+')';" ;
   Echo       "}else{" ;
   Echo       "html+=items_code.item(i).firstChild.data+' ('+items_libelle.item(i).firstChild.data+')';" ;
   Echo       "}" ;
   Echo       "html+='</option>';}" ;
   Echo      "html+='</select>';" ;
   Echo     "}" ;
   Echo    "else{html='';}" ;
   Echo    "document.getElementById(nom_champ).innerHTML=html;" ;
   Echo  "}else{" ;
   Echo    "var items_reponse=objet_http.responseXML.getElementsByTagName('reponse');" ;
   Echo    "if(items_reponse.length>0)" ;
   Echo     "{" ;
   Echo      "if(items_reponse.item(0).firstChild.data==1){" ;
   Echo      "document.getElementsByName('cell_clef_gestion')[0].style.background='".$l ["nom"]."';" ;
   Echo      "document.getElementsByName('cell_code_sconet')[0].style.background='".$l ["nom"]."';" ;
   Echo      "}else{" ;
   Echo      "document.getElementsByName('cell_clef_gestion')[0].style.background='red';" ;
   Echo      "document.getElementsByName('cell_code_sconet')[0].style.background='red';" ;
   Echo      "}" ;
   Echo     "}" ;
   Echo   "}" ;
   Echo "}" ;
   Echo "function efface_div(){document.getElementById('code_gestion').innerHTML='';document.getElementById('code_sconet').innerHTML='';}" ;
   Echo "</script>" ;
  }
 Echo "</head>" ;

 Echo "<BODY BACKGROUND=\"../images/fond.png\" TEXT=\"#000000\" onContextMenu=\"return false\">" ;
 Echo "<CENTER><FONT COLOR=\"#0000FF\"><B>Gestion&nbsp;des&nbsp;".$intitule_page [2].".</B></FONT></CENTER>" ;
 Echo "<TABLE ALIGN=\"CENTER\" BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"0\" STYLE=\"border-collapse:collapse\">" ;
 Echo "<TR><TD><TABLE ALIGN=\"CENTER\" BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"0\" BGCOLOR=\"".$l ["lien"]."\" STYLE=\"border:1px solid #000000;border-collapse:collapse\">" ;
 Echo "<TR><TD COLSPAN=\"4\">" ;
 Echo "<form method=\"post\" action=\"./gestion_disciplines.php\" name=\"ajout\" onSubmit=\"return verifie()\" autocomplete=\"off\">" ;
 Echo "<TABLE ALIGN=\"CENTER\" BORDER=\"0\" WIDTH=\"100%\" STYLE=\"border-collapse:collapse\">" ;
 Echo "<TR><TD ALIGN=\"CENTER\" COLSPAN=\"7\">&nbsp;<B>" ;
 If ($requete == 0) { Echo "Ajouter&nbsp;".$intitule_page [1] ; } Else { Echo "Modifier&nbsp;".$intitule_page [1] ; }
 Echo "</B>&nbsp;</TD></TR>" ;
 $resultats = SQL_commande ("SELECT * FROM types_disciplines ORDER BY nom", $id_sql) ;
 Echo "<TR BGCOLOR=\"".$l ["nom"]."\">" ;
 If (SQL_nbr_lignes ($resultats) > 0) { Echo "<TD ALIGN=\"CENTER\"><a href=\"./gestion_disciplines.php?requete=4\"><img src=\"../images/rafraichissement.png\" border=\"0\"></a>&nbsp;<FONT SIZE=\"".$l ["titre"]."\">&nbsp;Categorie&nbsp;</font></TD>" ; }
 Else { Echo "<input type=\"hidden\" name=\"id_type_discipline\" value=\"0\">" ; }
 Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;Nom&nbsp;long&nbsp;</font></TD>" ;
 Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;Nom&nbsp;court&nbsp;</FONT></TD>" ;
 Echo "<TD ALIGN=\"CENTER\" name=\"cell_clef_gestion\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;Cl&eacute;&nbsp;de&nbsp;gestion&nbsp;</FONT></TD>" ;
 Echo "<TD ALIGN=\"CENTER\" name=\"cell_code_sconet\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;Code&nbsp;Sconet&nbsp;</FONT></TD>" ;
 Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;Type&nbsp;</FONT></TD>" ;
 Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;Moyenne&nbsp;</FONT></TD>" ;
 //Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;Arrondi&nbsp;</FONT></TD>" ;
 Echo "<TD BGCOLOR=\"".$l ["lien"]."\"></TD>" ;
 Echo "</TR>" ;
 Echo "<TR>" ;
 If (SQL_nbr_lignes ($resultats) > 0)
  {
   Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<SELECT NAME=\"id_type_discipline\"" ;
   If (($apb_actif == 1) And ($requete != 0)) { Echo " onfocus=\"javascript:efface_div();\"" ; }
   Echo ">" ;
   $dt [0] = 0 ;
   For ($i = 0 ; $i < SQL_nbr_lignes ($resultats) ; $i++)
    {
     $r = SQL_tableau_associatif ($resultats, "") ;
     If (($i > 0) And ($r ["nom"] == $r_old))
      {
       $dt [0]++ ;
       $dt [$dt [0]] = $r ["id_type_discipline"] ;
      }
     Else
      {
       Echo "<option value=\"".$r ["id_type_discipline"]."\"" ; If ($modif ["id_type_discipline"] == $r ["id_type_discipline"]) { Echo " selected" ; }
       Echo ">".$r ["nom"]."</option>" ;
       $r_old = $r ["nom"] ;
      }
    }
   // Purge des types de disciplines
   If ($dt [0] > 0)
    {
     $requete = "DELETE FROM types_disciplines WHERE " ;
     For ($i = 1 ; $i <= $dt [0] ; $i++)
      {
       If ($i > 1) { $requete .= " OR " ; }
       $requete .= "id_type_discipline='".$dt [$i]."'" ;
      }
     $ok = SQL_commande ($requete, $id_sql) ;
    }
   Echo "&nbsp;</FONT></TD>" ;
  }
 Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<INPUT TYPE=\"TEXT\" NAME=\"nom_long\" VALUE=\"".$modif ["nom_long"]."\" SIZE=\"31\" MAXLENGTH=\"40\"" ;
 If ($apb_actif == 1) { Echo " onfocus=\"javascript:efface_div();\"" ; }
 Echo ">&nbsp;</FONT></TD>" ;
 Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<INPUT TYPE=\"TEXT\" NAME=\"nom_court\" VALUE=\"".$modif ["nom_court"]."\" SIZE=\"21\" MAXLENGTH=\"20\"" ;
 If ($apb_actif == 1) { Echo " onfocus=\"javascript:efface_div();\"" ; }
 Echo ">&nbsp;</FONT></TD>" ;
 Echo "<td align=\"center\"><font size=\"".$l ["titre"]."\">&nbsp;<input type=\"text\" name=\"clef_gestion\" value=\"".$modif ["nom_bref"]."\" size=\"6\" maxlength=\"5\"" ;
 If ($apb_actif == 1)
  {
   Echo " id=\"clef_gestion\"" ;
   Echo " onkeyup=\"javascript:requete=1;ajax_transmission('./gestion_disciplines.php?ajax_requete=1&car='+document.getElementById('clef_gestion').value,true,'ajax_retour');\"" ;
   Echo " onfocus=\"javascript:efface_div();requete=1;ajax_transmission('./gestion_disciplines.php?ajax_requete=1&car='+document.getElementById('clef_gestion').value,true,'ajax_retour');\"" ;
   Echo " onchange=\"javascript:requete=3;ajax_transmission('./gestion_disciplines.php?ajax_requete=3&c1='+document.getElementById('clef_gestion').value+'&c2='+document.getElementById('code_disc').value,true,'ajax_retour');\"" ;
  }
 Echo ">&nbsp;</FONT></TD>" ;
 Echo "<td align=\"center\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<INPUT TYPE=\"TEXT\" NAME=\"code_disc\" VALUE=\"".$modif ["code"]."\" SIZE=\"7\" MAXLENGTH=\"6\"" ;
 //If (($apb_actif == 1) And ($requete != 0))
 If ($apb_actif == 1)
  {
   Echo " id=\"code_disc\"" ;
   Echo " onkeyup=\"javascript:requete=2;ajax_transmission('./gestion_disciplines.php?ajax_requete=2&car='+document.getElementById('code_disc').value,true,'ajax_retour');\"" ;
   Echo " onfocus=\"javascript:efface_div();requete=2;ajax_transmission('./gestion_disciplines.php?ajax_requete=2&car='+document.getElementById('code_disc').value,true,'ajax_retour');\"" ;
   Echo " onchange=\"javascript:requete=3;ajax_transmission('./gestion_disciplines.php?ajax_requete=3&c1='+document.getElementById('clef_gestion').value+'&c2='+document.getElementById('code_disc').value,true,'ajax_retour');\"" ;
  }
 Echo ">&nbsp;</FONT></TD>" ;
 Echo "<td align=\"center\"><font size=\"".$l ["titre"]."\"><select name=\"type_disc\"" ; If ($apb_actif == 1) { Echo " onfocus=\"javascript:efface_div();\"" ; }
 Echo ">" ;
 For ($i = 1 ; $i <= $types_disciplines [0][0] ; $i++)
  {
   Echo "<option value=\"".$types_disciplines [$i][1]."\"" ; If ($modif ["type_discipline"] == $types_disciplines [$i][1]) { Echo " selected" ; }
   Echo ">".$types_disciplines [$i][0]."</option>" ;
  }
 Echo "</select></td>" ;
 Echo "<td align=\"center\"><font size=\"".$l ["titre"]."\"><select name=\"type_moyenne\"" ; If ($apb_actif == 1) { Echo " onfocus=\"javascript:efface_div();\"" ; }
 Echo ">" ;
 For ($i = 1 ; $i <= $types_moyennes [0][0] ; $i++)
  {
   Echo "<option value=\"".$types_moyennes [$i][1]."\"" ; If ($modif ["type_moyenne"] == $types_moyennes [$i][1]) { Echo " selected" ; }
   Echo ">".$types_moyennes [$i][0]."</option>" ;
  }
 Echo "</select></td>" ;
 /*
 Echo "<td align=\"center\"><font size=\"".$l ["titre"]."\"><select name=\"type_arrondi\"><option value=\"0\"" ;
 If ($modif ["type_arrondi"] == 0) { Echo " selected" ; }
 Echo ">Sp&eacute;cifications&nbsp;globales</option>" ;
 For ($i = 1 ; $i <= nombre_arrondi () ; $i++)
  {
   Echo "<option value=\"".$i."\"" ; If ($modif ["type_arrondi"] == $i) { Echo " selected" ; }
   Echo ">".nom_arrondi ($i)."</option>" ;
  }
 Echo "</select></td>" ;
 */
 Echo "<TD ALIGN=\"CENTER\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"code\" VALUE=\"".$_SESSION ["code"]."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_discipline\" VALUE=\"".$modif ["id_discipline"]."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"ancien_code\" VALUE=\"".$modif ["code"]."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"requete\" VALUE=\"".$requete."\">" ;
 Echo "<INPUT TYPE=\"IMAGE\" SRC=\"../images/ajouter.png\" alt=\"Ajouter/Modifier une discipline\" value=\"Ajouter\" border=\"0\">" ;
 Echo "</TD>" ;
 Echo "</TR>" ;
 Echo "<tr><td colspan=\"" ;
 If ($apb_actif == 1)
  {
   Echo "3\">&nbsp;</td>" ;
   Echo "<td align=\"center\"><div id=\"code_gestion\"></div></td>" ;
   Echo "<td align=\"center\"><div id=\"code_sconet\"></div></td>" ;
   Echo "<td colspan=\"2\"></td>" ;
  } Else { Echo "7\">&nbsp;</td>" ; }
 Echo "</tr>" ;
 Echo "</TABLE>" ;
 Echo "</FORM>" ;
 Echo "</TD></TR></TABLE>" ;
 Echo "</TD></TR>" ;

 If ($requete == 0)
  {
   // Disciplines deja saisies
   $resultat = SQL_commande ("SELECT * FROM disciplines WHERE millesime='".$millesime."' ORDER BY nom_long,nom_court,nom_bref,code,id_type_discipline", $id_sql) ;
   If (SQL_nbr_lignes ($resultat))
    {
     $nbr_d = 0 ;
     Echo "<TR><TD align=\"center\" HEIGHT=\"5\"><div id=\"avertissement\"><b>Les disciplines sur fond rouge n'ont pas de <i>clef de gestion</i> ou de <i>code sconet</i> valide.</b></div></TD></TR>" ;
     Echo "<TR><TD><TABLE ALIGN=\"CENTER\" BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"0\" BGCOLOR=\"".$l ["couleur_fond"]."\" STYLE=\"border:1px solid #000000;border-collapse:collapse\">" ;
     Echo "<TR BGCOLOR=\"".$l ["lien"]."\">" ;
     Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\"><a href=\"./gestion_disciplines.php?requete=5\"><img src=\"../images/effacer.png\" border=\"0\"></a>&nbsp;<B>Act.</B>&nbsp;</FONT></TD>" ;
     Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Cat&eacute;gorie</B>&nbsp;</FONT></TD>" ;
     Echo "<TD ALIGN=\"LEFT\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Nom</B>&nbsp;</FONT></TD>" ;
     Echo "<TD ALIGN=\"LEFT\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Nom&nbsp;court</B>&nbsp;</FONT></TD>" ;
     Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Cl&eacute;&nbsp;de&nbsp;gestion</B>&nbsp;</FONT></TD>" ;
     Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Code&nbsp;Sconet</B>&nbsp;</FONT></TD>" ;
     Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<b>Type</b>&nbsp;</FONT></TD>" ;
     Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<b>Moyenne</b>&nbsp;</FONT></TD>" ;
     //Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<b>Arrondi</b>&nbsp;</FONT></TD>" ;
     Echo "</TR>\n" ;
     $nbr_disc_inutiles = 0 ;
     $nbr_disc_non_valides = 0 ;
     While ($ligne = SQL_tableau_associatif ($resultat, ""))
      {
       $verif_disc = SQL_commande ("SELECT id_service_prof FROM services_prof WHERE discipline='".$ligne ["id_discipline"]."' LIMIT 1", $id_sql) ;
       $nbr_d++ ;
       Echo "<TR" ;
       If (($apb_actif == 1) And (garennes_apb_discipline_sconet_existe ($ligne ["code"],$ligne ["nom_bref"]) == False))
       {
        Echo " bgcolor=\"red\" title=\"Clef de Gestion ou Code Sconet non valide.\"" ;
        $nbr_disc_non_valides++ ;
       }
       ElseIf ($nbr_d%2 == 0) { Echo " bgcolor=\"".$l ["nom"]."\"" ; }
       Echo "><TD ALIGN=\"CENTER\"><TABLE ALIGN=\"CENTER\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" WIDTH=\"100%\">" ;
       Echo "<TR>" ;
       Echo "<FORM ACTION=\"./gestion_disciplines.php\" METHOD=\"POST\">" ;
       Echo "<TD" ;
       $nbr = (SQL_nbr_lignes ($verif_disc) == 0)+($ligne ["type_discipline"] == 3) ;
       If ($nbr > 0) { Echo " COLSPAN=\"".$nbr."\"" ; }
       Echo ">" ;
       Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"code\" VALUE=\"".$_SESSION ["code"]."\">" ;
       Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_discipline\" VALUE=\"".$ligne ["id_discipline"]."\">" ;
       Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"code_disc\" VALUE=\"".$ligne ["code"]."\">" ;
       Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"requete\" VALUE=\"2\">" ;
       Echo "<INPUT TYPE=\"IMAGE\" SRC=\"../images/edition.png\" TITLE=\"&Eacute;diter la discipline\" BORDER=\"0\">" ;
       Echo "</TD>" ;
       Echo "</FORM>" ;
       If ($ligne ["type_discipline"] == 3)
        {
         Echo "<FORM ACTION=\"./gestion_disciplines_specifiques.php\" METHOD=\"POST\">" ;
         Echo "<TD" ; If (SQL_nbr_lignes ($verif_disc) == 0) { Echo " COLSPAN=\"2\"" ; }
         Echo ">" ;
         Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"code\" VALUE=\"".$_SESSION ["code"]."\">" ;
         Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_discipline\" VALUE=\"".$ligne ["id_discipline"]."\">" ;
         Echo "<INPUT TYPE=\"IMAGE\" SRC=\"../images/fiche.png\" TITLE=\"Param&eacute;trage de la discipline\" BORDER=\"0\">" ;
         Echo "</TD>" ;
         Echo "</FORM>" ;
        }
       If (SQL_nbr_lignes ($verif_disc) == 0)
        {
         Echo "<FORM ACTION=\"./gestion_disciplines.php\" METHOD=\"POST\" onSubmit=\"return valide('".Str_Replace ("'", " ", $ligne ["nom_long"])."')\">" ;
         Echo "<TD align=\"right\">" ;
         Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"code\" VALUE=\"".$_SESSION ["code"]."\">" ;
         Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_discipline\" VALUE=\"".$ligne ["id_discipline"]."\">" ;
         Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"code_disc\" VALUE=\"".$ligne ["code"]."\">" ;
         Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"requete\" VALUE=\"1\">" ;
         Echo "<INPUT TYPE=\"IMAGE\" SRC=\"../images/effacer.png\" TITLE=\"Supprimer la discipline\" BORDER=\"0\">" ;
         Echo "</TD>" ;
         Echo "</FORM>" ;
         $nbr_disc_inutiles++ ;
        }
       Echo "</TR></TABLE></TD>" ;
       $res = SQL_commande ("SELECT nom FROM types_disciplines WHERE id_type_discipline='".$ligne ["id_type_discipline"]."' LIMIT 1", $id_sql) ;
       Echo "<TD ALIGN=\"LEFT\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;" ;
       If (SQL_nbr_lignes ($res) == 1)
        {
         $r = SQL_ligne_suivante ($res) ;
         Echo $r [0] ;
        }
       Echo "&nbsp;</FONT></TD>" ;
       Echo "<TD ALIGN=\"LEFT\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;".$ligne ["nom_long"]."&nbsp;</FONT></TD>" ;
       Echo "<TD ALIGN=\"LEFT\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;".$ligne ["nom_court"]."&nbsp;</FONT></TD>" ;
       Echo "<TD ALIGN=\"LEFT\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;".$ligne ["nom_bref"]."&nbsp;</FONT></TD>" ;
       Echo "<TD ALIGN=\"CENTER\"><FONT SIZE=\"".$l ["titre"]."\">&nbsp;".$ligne ["code"]."&nbsp;</FONT></TD>" ;
       Echo "<td align=\"center\"><font size=\"".$l ["titre"]."\">&nbsp;".nom_type_discipline ($ligne ["type_discipline"])."&nbsp;</font></td>" ;
       Echo "<td align=\"center\"><font size=\"".$l ["titre"]."\">&nbsp;".nom_type_moyenne ($ligne ["type_moyenne"])."&nbsp;</font></td>" ;
       //Echo "<td align=\"center\"><font size=\"".$l ["titre"]."\">&nbsp;".nom_arrondi ((integer)$ligne ["type_arrondi"])."&nbsp;</font></td>" ;
       Echo "</TR>";
      }
     Echo "<TR BGCOLOR=\"".$l ["nom"]."\"><TD COLSPAN=\"8\" ALIGN=CENTER>&nbsp;<B>".$nbr_d."&nbsp;" ;
     If ($nbr_d > 1) { Echo $intitule_page [2] ; } Else { Echo $intitule_page [0] ; }
     If ($nbr_disc_inutiles > 0)
      {
       Echo "&nbsp;:&nbsp;".($nbr_d-$nbr_disc_inutiles)."&nbsp;utilis&eacute;e" ;
       If (($nbr_d-$nbr_disc_inutiles) > 1) { Echo "s" ; }
       Echo "&nbsp;et&nbsp;".$nbr_disc_inutiles."&nbsp;non&nbsp;utilis&eacute;e" ;
       If ($nbr_disc_inutiles > 1) { Echo "s" ; }
      }
     Echo ".</B>&nbsp;</TD></TR></TABLE>" ;
    }
   Else
    {
    }
  }
 Echo "</TD></TR></TABLE>" ;
 Echo "</form>" ;
 If (($nbr_disc_non_valides == 0) Or (($apb_actif == 1) And ($requete != 0)))
  {
   Echo "<script type=\"text/javascript\">" ;
   If ($nbr_disc_non_valides == 0) { Echo "document.getElementById('avertissement').style.visibility='hidden';" ; }
   If (($apb_actif == 1) And ($requete != 0)) { Echo "requete=3;ajax_transmission('./gestion_disciplines.php?ajax_requete=3&c1='+document.getElementById('clef_gestion').value+'&c2='+document.getElementById('code_disc').value,true,'ajax_retour');" ; }
   Echo "</script>" ;
  }
 Echo "</body></html>" ;
?>